<template>
  <div class="list-table">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="wfUsedOpinionList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('快捷意见')" align="center" prop="opinions" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改快捷意见对话框 -->
    <el-dialog :title="$t(title)" width="30%" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
      <wfUsedOpinionForm ref="wfUsedOpinionForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listWfUsedOpinion, delWfUsedOpinion } from '@/api/act/task/wfUsedOpinion'
import wfUsedOpinionForm from './wfUsedOpinionForm.vue'
export default {
  components: {
    wfUsedOpinionForm
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 快捷意见表格数据
          wfUsedOpinionList: [],
          // 弹出层标题
          title: '快捷意见',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              userId: undefined,
              opinions: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询快捷意见列表 */
    getList() {
        this.loading = true
        listWfUsedOpinion(this.queryParams).then(response => {
            this.wfUsedOpinionList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            userid: undefined,
            opinions: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.wfUsedOpinionForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.wfUsedOpinionForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delWfUsedOpinion(row.id)
        }).then(() => {
            this.getList()
            this.$parent.$parent.listWfUsedOpinion()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.dialogForm{
  height: 30%;
  overflow: auto;
}

</style>
